vimfandomcom-20200223-history
Using marks
A mark allows you to record your current position so you can return to it later. There is no visible indication of where marks are set. Each file has a set of marks identified by lowercase letters (a-z). In addition there is a global set of marks identified by uppercase letters (A-Z) that identify a position within a particular file. For example, you may be editing ten files. Each file could have mark a''', but only one file can have mark '''A. Because of their limitations, uppercase marks may at first glance seem less versatile than their lowercase counterpart, but this feature allows them to be used as a quick sort of "file bookmark." For example, open your .vimrc, press mV, and close Vim. The next time you want to edit your .vimrc, just press 'V to open it. This assumes that you have kept the default behavior, so that uppercase marks are all remembered in the between Vim sessions. As well as the letter marks, there are various special marks. The marks for recently-edited files are saved (provided the 'viminfo' option has the '''' parameter), so marks from previous sessions can be used when editing in the future. Setting marks To set a mark, type m followed by a letter. For example, ma sets mark '''a at the current position (line and column). If you set mark a''', any mark in the current file that was previously identified as '''a is removed. If you set mark A''', any previous mark '''A (in any file) is removed. Using marks To jump to a mark enter an apostrophe (') or backtick (`) followed by a letter. Using an apostrophe jumps to the beginning of the line holding the mark, while a backtick jumps to the line and column of the mark. Using a lowercase letter (for example `a) will only work if that mark exists in the current buffer. Using an uppercase letter (for example `A) will jump to the file and the position holding the mark (you do not need to open the file prior to jumping to the mark). *Each file can have mark a''' – use a lowercase mark to jump within a file. *There is only one file mark '''A – use an uppercase mark to jump between files. Commands like d'a operate "linewise" and include the start and end lines. Commands like d`a operate "characterwise" and include the start but not the end character. It is possible to navigate between lowercase marks: The above commands take a count. For example, 5]` jumps to the fifth mark after the cursor. Special marks Vim has some special marks which it sets automatically. Here are some of the most useful: See the full list at and following. Deleting marks If you delete a line containing a mark, the mark is also deleted. If you wipeout a buffer (command :bw), all marks for the buffer are deleted. The :delmarks command (abbreviated as :delm) may be used to delete specified marks. See also * plugin to put a sign in the left margin for each mark; works poorly and interferes with other commands in Vim 7 (updated version working in 7.4 here: https://github.com/jacquesbh/vim-showmarks) * is another showmarks plugin which works without problems in Vim 7 References * Comments The :delmarks command requires Vim 7.0. On previous versions, a kludge to remove all marks is to enter the command :%!cat (on Unix-based systems), or :%!type (on Windows) to delete the entire contents of the buffer and replace each line with itself by filtering through an external command. A mark is automatically deleted when its line is deleted. ---- I suggest moving the Deleting section below the Using section. (Spiiph 11:53, 30 July 2009 (UTC)) :I was scratching my head wondering why I put them in their current order, but when I went to move it, I see why. It's nice that "Using" and "Special" can be seen together, on the same screen because they are the items that a reader will probably want to refer to (it's a bit hard to keep all of it in your mind). I suppose "Deleting" could go after "Special", but that might be as strange as where it is now? JohnBeckett 23:34, 30 July 2009 (UTC) ::I think that would be better, even though it might seem illogical. Another idea would be to remove the section on Deleting marks altogether. I don't think I have ever used that functionality, and users who need it are probably advanced enough to find the information in the :help. (Spiiph 13:39, 2 August 2009 (UTC)) :::Done.